home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl / 5.10.0 / Module / Build / ConfigData.pm < prev    next >
Encoding:
Perl POD Document  |  2009-06-26  |  6.0 KB  |  195 lines

  1. package Module::Build::ConfigData;
  2. use strict;
  3. my $arrayref = eval do {local $/; <DATA>}
  4.   or die "Couldn't load ConfigData data: $@";
  5. close DATA;
  6. my ($config, $features, $auto_features) = @$arrayref;
  7.  
  8. sub config { $config->{$_[1]} }
  9.  
  10. sub set_config { $config->{$_[1]} = $_[2] }
  11. sub set_feature { $features->{$_[1]} = 0+!!$_[2] }  # Constrain to 1 or 0
  12.  
  13. sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features }
  14.  
  15. sub feature_names {
  16.   my @features = (keys %$features, auto_feature_names());
  17.   @features;
  18. }
  19.  
  20. sub config_names  { keys %$config }
  21.  
  22. sub write {
  23.   my $me = __FILE__;
  24.   require IO::File;
  25.   require Data::Dumper;
  26.  
  27.   my $mode_orig = (stat $me)[2] & 07777;
  28.   chmod($mode_orig | 0222, $me); # Make it writeable
  29.   my $fh = IO::File->new($me, 'r+') or die "Can't rewrite $me: $!";
  30.   seek($fh, 0, 0);
  31.   while (<$fh>) {
  32.     last if /^__DATA__$/;
  33.   }
  34.   die "Couldn't find __DATA__ token in $me" if eof($fh);
  35.  
  36.   local $Data::Dumper::Terse = 1;
  37.   seek($fh, tell($fh), 0);
  38.   $fh->print( Data::Dumper::Dumper([$config, $features, $auto_features]) );
  39.   truncate($fh, tell($fh));
  40.   $fh->close;
  41.  
  42.   chmod($mode_orig, $me)
  43.     or warn "Couldn't restore permissions on $me: $!";
  44. }
  45.  
  46. sub feature {
  47.   my ($package, $key) = @_;
  48.   return $features->{$key} if exists $features->{$key};
  49.   
  50.   my $info = $auto_features->{$key} or return 0;
  51.   
  52.   # Under perl 5.005, each(%$foo) isn't working correctly when $foo
  53.   # was reanimated with Data::Dumper and eval().  Not sure why, but
  54.   # copying to a new hash seems to solve it.
  55.   my %info = %$info;
  56.   
  57.   require Module::Build;  # XXX should get rid of this
  58.   while (my ($type, $prereqs) = each %info) {
  59.     next if $type eq 'description' || $type eq 'recommends';
  60.     
  61.     my %p = %$prereqs;  # Ditto here.
  62.     while (my ($modname, $spec) = each %p) {
  63.       my $status = Module::Build->check_installed_status($modname, $spec);
  64.       if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
  65.     }
  66.   }
  67.   return 1;
  68. }
  69.  
  70.  
  71. =head1 NAME
  72.  
  73. Module::Build::ConfigData - Configuration for Module::Build
  74.  
  75.  
  76. =head1 SYNOPSIS
  77.  
  78.   use Module::Build::ConfigData;
  79.   $value = Module::Build::ConfigData->config('foo');
  80.   $value = Module::Build::ConfigData->feature('bar');
  81.   
  82.   @names = Module::Build::ConfigData->config_names;
  83.   @names = Module::Build::ConfigData->feature_names;
  84.   
  85.   Module::Build::ConfigData->set_config(foo => $new_value);
  86.   Module::Build::ConfigData->set_feature(bar => $new_value);
  87.   Module::Build::ConfigData->write;  # Save changes
  88.  
  89.  
  90. =head1 DESCRIPTION
  91.  
  92. This module holds the configuration data for the C<Module::Build>
  93. module.  It also provides a programmatic interface for getting or
  94. setting that configuration data.  Note that in order to actually make
  95. changes, you'll have to have write access to the C<Module::Build::ConfigData>
  96. module, and you should attempt to understand the repercussions of your
  97. actions.
  98.  
  99.  
  100. =head1 METHODS
  101.  
  102. =over 4
  103.  
  104. =item config($name)
  105.  
  106. Given a string argument, returns the value of the configuration item
  107. by that name, or C<undef> if no such item exists.
  108.  
  109. =item feature($name)
  110.  
  111. Given a string argument, returns the value of the feature by that
  112. name, or C<undef> if no such feature exists.
  113.  
  114. =item set_config($name, $value)
  115.  
  116. Sets the configuration item with the given name to the given value.
  117. The value may be any Perl scalar that will serialize correctly using
  118. C<Data::Dumper>.  This includes references, objects (usually), and
  119. complex data structures.  It probably does not include transient
  120. things like filehandles or sockets.
  121.  
  122. =item set_feature($name, $value)
  123.  
  124. Sets the feature with the given name to the given boolean value.  The
  125. value will be converted to 0 or 1 automatically.
  126.  
  127. =item config_names()
  128.  
  129. Returns a list of all the names of config items currently defined in
  130. C<Module::Build::ConfigData>, or in scalar context the number of items.
  131.  
  132. =item feature_names()
  133.  
  134. Returns a list of all the names of features currently defined in
  135. C<Module::Build::ConfigData>, or in scalar context the number of features.
  136.  
  137. =item auto_feature_names()
  138.  
  139. Returns a list of all the names of features whose availability is
  140. dynamically determined, or in scalar context the number of such
  141. features.  Does not include such features that have later been set to
  142. a fixed value.
  143.  
  144. =item write()
  145.  
  146. Commits any changes from C<set_config()> and C<set_feature()> to disk.
  147. Requires write access to the C<Module::Build::ConfigData> module.
  148.  
  149. =back
  150.  
  151.  
  152. =head1 AUTHOR
  153.  
  154. C<Module::Build::ConfigData> was automatically created using C<Module::Build>.
  155. C<Module::Build> was written by Ken Williams, but he holds no
  156. authorship claim or copyright claim to the contents of C<Module::Build::ConfigData>.
  157.  
  158. =cut
  159.  
  160. __DATA__
  161.  
  162. [
  163.           {},
  164.           {},
  165.           {
  166.             'YAML_support' => {
  167.                                 'requires' => {
  168.                                                 'YAML' => ' >= 0.35, != 0.49_01 '
  169.                                               },
  170.                                 'description' => 'Use YAML.pm to write META.yml files'
  171.                               },
  172.             'manpage_support' => {
  173.                                    'requires' => {
  174.                                                    'Pod::Man' => 0
  175.                                                  },
  176.                                    'description' => 'Create Unix man pages'
  177.                                  },
  178.             'C_support' => {
  179.                              'requires' => {
  180.                                              'ExtUtils::CBuilder' => '0.15'
  181.                                            },
  182.                              'recommends' => {
  183.                                                'ExtUtils::ParseXS' => '1.02'
  184.                                              },
  185.                              'description' => 'Compile/link C & XS code'
  186.                            },
  187.             'HTML_support' => {
  188.                                 'requires' => {
  189.                                                 'Pod::Html' => 0
  190.                                               },
  191.                                 'description' => 'Create HTML documentation'
  192.                               }
  193.           }
  194.         ]
  195.